package njitzx;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class test {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        try {
            Class<?> aClass = Class.forName("njitzx.User");
            User user = (User) aClass.newInstance();
            user.name = "Tom";
            System.out.println(user.name);
            user.eat();
            //通过Usre类调用eat方法
            Method method = User.class.getMethod("eat");
            method.invoke(user);


        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
